﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows;
using BaMusaSoft.RPS.ViewModel;

namespace BaMusaSoft.RPS.View.Services
{
    internal class Helper
    {

        internal static void EnumeratVisual(Visual myVisual, string name)
        {
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)
            {

                // Retrieve child visual at specified index value.
                Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);

                if (childVisual is TextBox)
                {
                    var text = childVisual as TextBox;
                    var exp = text.GetBindingExpression(TextBox.TextProperty);
                    if (exp != null && exp.ParentBinding.Path.Path == name)
                    {
                        text.Focus();
                    }
                    else
                    {
                        EnumeratVisual(childVisual, name);
                    }

                }
                else
                {
                    // Enumerate children of the child visual object.
                    EnumeratVisual(childVisual, name);
                }
            }
        }
        internal static MessageBoxResult ConfirmationMessageBox(string msg)
        {
            return MessageBox.Show(msg, "RPS", MessageBoxButton.YesNo,
                                   MessageBoxImage.Question, 
                                   MessageBoxResult.No,
                                   MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
        }
        internal static void NotificationMessageBox(string msg)
        {
            MessageBox.Show(msg, "RPS", MessageBoxButton.OK, 
                          MessageBoxImage.Information, 
                          MessageBoxResult.OK, 
                          MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
        }

        //internal static void MessageNotificationEvent(object sender, NotificationEventArgs e)
        //{
        //    NotificationMessageBox(e.Message);
        //}

        //internal static void AskQuestionEvent(object sender, NotificationEventArgs<string, bool> e)
        //{
        //    MessageBoxResult result = ConfirmationMessageBox(e.Message);
        //    if (result == MessageBoxResult.Yes)
        //    {
        //        e.Completed(true);
        //    }
        //    else
        //    {
        //        e.Completed(false);
        //    }
        //}
        
    }
}
